﻿using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
/// Summary description for TimespanExtensions
/// </summary>
public static class TimespanExtensions
{
    public static string HowLongAgo(DateTime when)
    {
        return ToNaturalLanguageString(DateTime.Now - when);
    }

    private static string ToNaturalLanguageString(TimeSpan span)
    {
        if (span.Days == 1)
        {
            return "One day ago";
        }
        if (span.Days > 1)
        {
            return String.Format("{0} days ago", span.Days);
        }
        if (span.Hours == 1)
        {
            return "One hour ago";
        }
        if (span.Hours > 1)
        {
            return String.Format("{0} hours ago", span.Hours);
        }
        if (span.Minutes == 1)
        {
            return "One minute ago";
        }
        if (span.Minutes > 1)
        {
            return String.Format("{0} minutes ago", span.Minutes);
        }
        return "Just now";
    }

}
